package com.jh3502.vivo.function.tododetail.travel;

/**
 * @author harisucici
 * @date 2017/6/19
 */

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.jh3502.vivo.R;
import com.jh3502.vivo.view.MyRecyclerView;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class TodoDetailChangeAdapter extends RecyclerView.Adapter<TodoDetailChangeAdapter.ViewHolder> {


    private Context mContext;
    private List<TodoDetailChangeBean> listItems;
    private View convertView;
    private TodoDetailChangeTasAdapter mTasAdapter;
    private TodoDetailChangeCrsAdapter mCrsAdapter;
    private String name;

    public TodoDetailChangeAdapter(Context context, List<TodoDetailChangeBean> datas) {
        this.listItems = datas;
        this.mContext = context;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int viewType) {
        convertView = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.item_todo_detail_travel_change, viewGroup, false);
        ViewHolder vh = new ViewHolder(convertView);
        return vh;
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder viewHolder, final int position) {
        viewHolder.itemView.setTag(position);
        if (position == 0) {
            viewHolder.itemTodoDetailTitle.setText(name + "提出申请");

        } else {
            viewHolder.itemTodoDetailTitle.setText("变更申请");

        }
        viewHolder.itemTodoDetailDate.setText(listItems.get(position).getCreatedate());

        if (listItems.get(position).getTas().size() == 0) {
            viewHolder.itemTodoDetailTas.setVisibility(View.GONE);
        } else {
            viewHolder.itemTodoDetailTas.setVisibility(View.VISIBLE);
            mTasAdapter = new TodoDetailChangeTasAdapter(mContext, listItems.get(position).getTas());
            viewHolder.itemTodoDetailTas.setNestedScrollingEnabled(false);
            viewHolder.itemTodoDetailTas.setAdapter(mTasAdapter);
        }
        if (listItems.get(position).getCrs().size() == 0) {
            viewHolder.itemTodoDetailCrs.setVisibility(View.GONE);
        } else {
            viewHolder.itemTodoDetailCrs.setVisibility(View.VISIBLE);
            mCrsAdapter = new TodoDetailChangeCrsAdapter(mContext, listItems.get(position).getCrs());
            viewHolder.itemTodoDetailCrs.setNestedScrollingEnabled(false);
            viewHolder.itemTodoDetailCrs.setAdapter(mCrsAdapter);
        }


    }


    @Override
    public int getItemCount() {
        return listItems.size();
    }

    public void setName(String name) {
        this.name = name;
    }

    public static class ViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.item_todo_detail_title)
        TextView itemTodoDetailTitle;
        @BindView(R.id.item_todo_detail_date)
        TextView itemTodoDetailDate;
        @BindView(R.id.item_todo_detail_crs)
        MyRecyclerView itemTodoDetailCrs;
        @BindView(R.id.item_todo_detail_tas)
        MyRecyclerView itemTodoDetailTas;

        public ViewHolder(@NonNull View view) {

            super(view);
            ButterKnife.bind(this, view);
        }
    }


}